package com.xinda.admin.controller;

import java.util.Properties;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xinda.admin.service.CountService;
import com.xinda.admin.vo.CountNumVO;
import com.xinda.admin.vo.LastLoginVO;
/**
 * 
	* <p>Title:BaseController </p>
	* <p>Description: 首页</p>
	* <p>Company: </p> 
	* @author Administrator
	* @date 2017年8月23日下午4:20:06
 */
@Controller
public class BaseController {
	@Resource
	private CountService countService;
	/**
	 * 后台管理系统首页
	 * @return
	 */
	@RequestMapping(value = "/index")
	public String index(HttpSession session) {
		Integer isLogin = (Integer) session.getAttribute("isLogin");
		if (isLogin!=null) {
			return "admin/index";
		}
		return "admin/login";
	}
	/**
	 * 后台管理系统欢迎界面
	 * @return
	 */
	@RequestMapping(value = "/welcome")
	public String welcome(Model model) {
		Integer id = 1;
		
		/*统计上次登录信息*/
		LastLoginVO lastLogin = countService.lastLogin(id);
		
		/*统计全部数据*/
		CountNumVO countNum = countService.countNum();
		
		/*统计今天数据*/
		CountNumVO countNumToday = countService.countNumToday();
		
		/*统计昨天数据*/
		CountNumVO countNumYesterday = countService.countNumYesterday();
		
		/*统计本周数据*/
		CountNumVO countNumWeek = countService.countNumWeek();
		
		/*统计本月数据*/
		CountNumVO countNumMonth = countService.countNumMonth();
		
		/*获取当前操作系统*/
		Properties props = System.getProperties();
		String osName = props.getProperty("os.name");
		
		model.addAttribute("lastLogin", lastLogin);
		model.addAttribute("osName", osName);
		model.addAttribute("countNum",countNum);
		model.addAttribute("countNumToday",countNumToday);
		model.addAttribute("countNumYesterday",countNumYesterday);
		model.addAttribute("countNumWeek",countNumWeek);
		model.addAttribute("countNumMonth",countNumMonth);
		
		return "admin/welcome";
	}
}
